image: Implement clipping support for icon-shadow
authorBenjamin Otte <otte@redhat.com>
Wed, 1 Oct 2014 04:04:19 +0000 (06:04 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 3 Oct 2014 04:18:04 +0000 (06:18 +0200)
Testcase is attached.

gtk/gtkimage.c
testsuite/reftests/Makefile.am
testsuite/reftests/image-icon-shadow-clipping.css [new file with mode: 0644]
testsuite/reftests/image-icon-shadow-clipping.ref.ui [new file with mode: 0644]
testsuite/reftests/image-icon-shadow-clipping.ui [new file with mode: 0644]

index 80b514d98f3236a2d499f3329d403de27d8e2e47..a50298cad2457d0e181ed0022aeb1fb4f54a9ad8 100644 (file)
@@ -38,6 +38,9 @@
 #include "gtkintl.h"
 #include "gtkprivate.h"
 #include "gtktypebuiltins.h"
+#include "gtkcssshadowsvalueprivate.h"
+#include "gtkstylecontextprivate.h"
+#include "gtkwidgetprivate.h"
 
 #include "a11y/gtkimageaccessible.h"
 
@@ -146,6 +149,8 @@ struct _GtkImagePrivate
 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_BUTTON
 static gint gtk_image_draw                 (GtkWidget    *widget,
                                             cairo_t      *cr);
+static void gtk_image_size_allocate        (GtkWidget    *widget,
+                                            GtkAllocation*allocation);
 static void gtk_image_unmap                (GtkWidget    *widget);
 static void gtk_image_realize              (GtkWidget    *widget);
 static void gtk_image_unrealize            (GtkWidget    *widget);
@@ -218,6 +223,7 @@ gtk_image_class_init (GtkImageClass *class)
   widget_class->get_preferred_width = gtk_image_get_preferred_width;
   widget_class->get_preferred_height = gtk_image_get_preferred_height;
   widget_class->get_preferred_height_and_baseline_for_width = gtk_image_get_preferred_height_and_baseline_for_width;
+  widget_class->size_allocate = gtk_image_size_allocate;
   widget_class->unmap = gtk_image_unmap;
   widget_class->realize = gtk_image_realize;
   widget_class->unrealize = gtk_image_unrealize;
@@ -1522,6 +1528,26 @@ gtk_image_reset_anim_iter (GtkImage *image)
     }
 }
 
+static void
+gtk_image_size_allocate (GtkWidget     *widget,
+                         GtkAllocation *allocation)
+{
+  GtkBorder extents;
+  GtkAllocation clip;
+
+  GTK_WIDGET_CLASS (gtk_image_parent_class)->size_allocate (widget, allocation);
+
+  /* XXX: This is not strictly correct, we could compute the area
+   * actually occupied by the image, but I'm lazy...
+   */
+  _gtk_css_shadows_value_get_extents (_gtk_style_context_peek_property (gtk_widget_get_style_context (widget), GTK_CSS_PROPERTY_ICON_SHADOW), &extents);
+  clip.x = allocation->x - extents.left;
+  clip.width = allocation->width + extents.left + extents.right;
+  clip.y = allocation->y - extents.top;
+  clip.height = allocation->height + extents.top + extents.bottom;
+  _gtk_widget_set_simple_clip (widget, &clip);
+}
+
 static void
 gtk_image_unmap (GtkWidget *widget)
 {
index 39cd5f146c6ef370c3fc09aef41bb1dd9fcb518c..47c4864c9762976c85b0151434524ef238619325 100644 (file)
@@ -268,6 +268,9 @@ testdata = \
        iconview-empty.css \
        iconview-empty.ui \
        iconview-empty.ref.ui \
+       image-icon-shadow-clipping.css \
+       image-icon-shadow-clipping.ref.ui \
+       image-icon-shadow-clipping.ui \
        image-load-from-file.css \
        image-load-from-file.ref.ui \
        image-load-from-file.ui \
diff --git a/testsuite/reftests/image-icon-shadow-clipping.css b/testsuite/reftests/image-icon-shadow-clipping.css
new file mode 100644 (file)
index 0000000..4770cc1
--- /dev/null
@@ -0,0 +1,5 @@
+@import "reset-to-defaults.css";
+
+GtkImage {
+  icon-shadow: 20px 20px tomato;
+}
diff --git a/testsuite/reftests/image-icon-shadow-clipping.ref.ui b/testsuite/reftests/image-icon-shadow-clipping.ref.ui
new file mode 100644 (file)
index 0000000..c670508
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">100</property>
+    <property name="height_request">100</property>
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <child>
+      <object class="GtkImage" id="image1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="icon_name">edit-delete</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/image-icon-shadow-clipping.ui b/testsuite/reftests/image-icon-shadow-clipping.ui
new file mode 100644 (file)
index 0000000..1bddc5a
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">100</property>
+    <property name="height_request">100</property>
+    <property name="can_focus">False</property>
+    <property name="type">popup</property>
+    <child>
+      <object class="GtkBox" id="box2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">center</property>
+        <property name="valign">center</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkImage" id="image1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="icon_name">edit-delete</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>